const send = require("../config/MailConfig");
const moment = require("moment");
const jsonwebtoken = require("jsonwebtoken");
const config = require("../config/index");
class LoginController {
  constructor() {}

  async forget(ctx) {
    const { body } = ctx.request;
    try {
      // 查询数据库是否有用户

      let result = await send({
        code: "1234",
        expire: moment().add(30, "minutes").format("YYYY-MM-DD HH:mm:ss"),
        email: "1511491804@qq.com",
        user: "liyunfu",
      });
      ctx.body = {
        code: 200,
        data: result,
        meg: "邮件发送成功",
      };
    } catch (error) {
      console.log(error);
    }
  }
  async login(ctx) {
    // 接收用户的数据
    // 返回token

    console.log(ctx.body);
    let token = jsonwebtoken.sign(
      {
        _id: "liyunfu",
        exp: Math.floor(Date.now() / 1000) + 60 * 60 * 24,
      },
      config.JWT_SECRET
    );
    ctx.body = {
      code: 200,
      token,
    };
  }
}

module.exports = new LoginController();
